<template>
  <div class="container2">
    <el-card class="logainCard-mobile hidden-md-and-up" key="login">
      <div style="text-align: center; font-size: 13pt; color: white">
        账号登录
      </div>
      <div class="center">
        <i class="el-icon-user" style="color: white"></i>
        <el-input
          style="width: 90%; margin-left: 10px"
          placeholder="请输入账户(邮箱)"
          v-model="email"
        ></el-input>
      </div>
      <div class="center" style="margin-top: 20px">
        <i class="el-icon-lock" style="color: white"></i>
        <el-input
          type="password"
          style="width: 90%; margin-left: 10px"
          placeholder="请输入密码"
          v-model="password"
        ></el-input>
      </div>
      <div class="tbtn" style="margin-top: 20px">
        <el-button style="width: 100%" class="btn" v-on:click="login"
          >登录</el-button
        >
        <!-- //绑定了鼠标点击事件 -->
      </div>
    </el-card>
    <el-card class="loginCard hidden-sm-and-down">
      <div style="text-align: center; font-size: 13pt; color: white">
        账号登录
      </div>
      <div class="center">
        <i class="el-icon-user" style="color: white"></i>
        <el-input
          style="width: 90%; margin-left: 10px"
          placeholder="请输入账户(邮箱)"
          v-model="email"
        ></el-input>
      </div>
      <div class="center" style="margin-top: 20px">
        <i class="el-icon-lock" style="color: white"></i>
        <el-input
          type="password"
          style="width: 90%; margin-left: 10px"
          placeholder="请输入密码"
          v-model="password"
        ></el-input>
      </div>
      <div class="tbtn" style="margin-top: 20px">
        <el-button style="width: 100%" class="btn" v-on:click="login"
          >登录</el-button
        >
        <!-- //绑定了鼠标点击事件 -->
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  props: {},
  data: function () {
    return {
      email: "",
      password: "",
    };
  },
  methods: {
    async login() {
      let request = {
        email: this.email,
        password: this.password,
      };
      let res = await this.$http.post("/user/login", request);
      if (res.statusCode == 200) {
        localStorage.setItem("token", res.token);
        localStorage.setItem("user", JSON.stringify(res.data));
        //跳转页面
        this.$router.push({ path: "/" });
      } else if (res.statusCode == 400) {
        this.tips("用户名和密码不能为空");
        //显示用户名或者密码错误
      } else if (res.statusCode == 401) {
        this.tips("用户名或者密码错误");
      }
    },
    tips(msg) {
      const h = this.$createElement;
      this.$notify({
        title: "结果",
        message: h("i", { style: "color: teal" }, msg),
      });
    },
  },
};
</script>

<style scoped>
.btn {
  background-color: rgba(0, 0, 0, 0);
  color: white;
}
.tbtn {
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
}
.btn:hover {
  color: black;
  background-color: white;
}
.btn:focus {
  background-color: rgba(0, 0, 0, 0);
  color: white;
}
.btn:active {
  color: black;
  background-color: white;
}
.center {
  margin-top: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.logainCard-mobile {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  flex-direction: column;
  /* background: gray;
		border: gray; */
  background: rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border: 0;
}
.loginCard {
  width: 400px;
  height: 300px;
  display: flex;
  justify-content: center;
  flex-direction: column;
  /* background: gray;
		border: gray; */
  background: rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border: 0;
}
.container2 {
  background-image: url("../assets/page.png");
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: white;
}
</style>